<template>
  <div style="padding:10px">
    <!-- 功能区 -->
    <el-row :gutter = "30">
      <el-col :span="18">
        <!--搜索区-->
        <Search refs="pannelsearch" v-model="value"  @searchmethod = "searchm"></Search>
      </el-col>
      <el-col :span="6">
        <!-- 按钮操作区 
        <pannel-operation refs="operationpannel" :items="btnItems" @create="create($event)"></pannel-operation>--> 
      </el-col>
    </el-row>
    <!-- 过滤细节展示 
    <el-row>
      <el-col>
        <pannel-filter-detail v-if="value.filters.isShow"></pannel-filter-detail>
      </el-col>
    </el-row>-->
    <el-row>
      <el-col>
        <PannelGrid v-model="value"></PannelGrid>
      </el-col>
    </el-row>
  </div>  
</template>
<script>
  import Search     from './components/search'
  import PannelGrid from './components/pannelgrid'
  import { treeDataTranslate, treeToArrayList, getChildNodeFromArray } from '@/utils'
  export default {
    name: 'SearchPannelTreeMaxin',
    props: {
      value: {
        type: Object,
        default: {}
      },
      setsearchcondition: {
        type: Function
      },
      btnItems: {
        type: Array,
        default: []
      }
    },
    components: {
      Search,
      PannelGrid
    },
    data() {
      return {
        rs: 'this is '
      }
    },
    mounted(){
      this.searchm()  
    },
    methods: {
      searchm(){
        const _this = this
        _this.$nextTick(() => {
          if(typeof(_this.setsearchcondition) === 'function'){
            _this.value.searchOperation.searchresult = 
            _this.setsearchcondition(_this.value.searchOperation.searchresult)
          }
          if(typeof(_this.value.searchOperation.r) === 'function'){
            let r = _this.value.searchOperation.r 
            r(_this.value.searchOperation).then( ({data}) => {
              if(typeof(_this.value.searchOperation.aftersearch) === 'function'){
                data = _this.value.searchOperation.aftersearch(data)
              }
              _this.value.gridOperation.datalist = treeDataTranslate(data, 'Id','Parentid')
            }).catch((error) => {
            })
          }
        })
      },
      create(){
        this.$emit('create')
      }
    }
  }
</script>